package com.cloud.mall.exp;

import com.cloud.mall.enums.ExcEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;


/**
 * @Author: 梁二东
 * @Date: 2024/12/4 15:37
 * @Description:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class CustomException extends RuntimeException {

    /**
     * 异常码
     */
    private Integer code;

    /**
     * 已知的异常信息
     */
    private String message;

    /**
     * 请求url
     */
    private String path;

    /**
     * get,post,...
     */
    private String method;

    public static CustomException fail(ExcEnum excEnum) {
        return fail(excEnum.getCode(), excEnum.getMessage(), "", "");
    }

    public static CustomException failPost(ExcEnum excEnum, String path) {
        return fail(excEnum.getCode(), excEnum.getMessage(), path, "POST");
    }

    public static CustomException failGet(ExcEnum excEnum, String path) {
        return fail(excEnum.getCode(), excEnum.getMessage(), path, "GET");
    }

    public static CustomException failPost(Integer code, String message, String path) {
        return fail(code, message, path, "POST");
    }

    public static CustomException failGet(Integer code, String message, String path) {
        return fail(code, message, path, "GET");
    }

    public static CustomException fail(Integer code, String message) {
        return new CustomException(code, message, "", "");
    }
    public static CustomException fail(Integer code, String message, String path, String method) {
        return new CustomException(code, message, path, method);
    }
}
